import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: LogoRotate());
  }
}

class RoateAnimationExample2 extends StatefulWidget {
  @override
  _RoateAnimationExample2State createState() => _RoateAnimationExample2State();
}

class _RoateAnimationExample2State extends State<RoateAnimationExample2> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('旋转动画示例')),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            AnimatedRotation(
              //0.25 1/4  1 360度
              turns: 0.25,
              duration: Duration(seconds: 2),
              alignment: Alignment(0, 0),
              curve: Curves.bounceIn,
              onEnd: () {
                //动画结束 的回调
              },
              child: Container(width: 250, height: 110, color: Colors.red),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.change_circle_outlined),
        onPressed: () {},
      ),
    );
  }
}

class LogoRotate extends StatefulWidget {
  const LogoRotate({super.key});

  @override
  State<LogoRotate> createState() => LogoRotateState();
}

class LogoRotateState extends State<LogoRotate> {
  double turns = 0.0;

  void _changeRotation() {
    setState(() => turns += 1.0 / 8.0); // 每次旋转1/8圈（45度）
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        ElevatedButton(onPressed: _changeRotation, child: const Text('旋转Logo')),
        Padding(
          padding: const EdgeInsets.all(50),
          child: AnimatedRotation(
            turns: turns, // 旋转圈数
            duration: const Duration(seconds: 2), // 动画时长
            child: Container(width: 250, height: 110, color: Colors.red),
          ),
        ),
      ],
    );
  }
}
